<template>
  <el-dialog title="新增合作商" :visible="dialogVisible" @close="handleClose">
    <el-form ref="roleDialogForm" label-width="120px" :model="roleForm" :rules="rules">
      <el-form-item prop="name" label="合作商名称">
        <el-input v-model="roleForm.name" placeholder="请输入" maxlength="10" show-word-limit />
      </el-form-item>
      <el-form-item prop="contact" label="联系人">
        <el-input v-model="roleForm.contact" placeholder="请输入" maxlength="10" show-word-limit />
      </el-form-item>
      <el-form-item prop="mobile" label="联系电话">
        <el-input v-model="roleForm.mobile" placeholder="请输入" maxlength="11" show-word-limit />
      </el-form-item>
      <el-form-item prop="ratio" label="分成比例">
        <el-input-number v-model="roleForm.ratio" controls-position="right" :min="1" @change="handleChange" />
      </el-form-item>
      <el-form-item prop="account" label="账号">
        <el-input v-model="roleForm.account" placeholder="请输入" maxlength="18" show-word-limit />
      </el-form-item>
      <el-form-item prop="password" label="密码">
        <el-input v-model="roleForm.password" placeholder="请输入" maxlength="20" show-word-limit />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button v-loading="loading" type="primary" @click="handleSumit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addPartnerApi } from '@/api/point'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleForm: {
        name: '',
        contact: '',
        mobile: '',
        ratio: 1,
        account: '',
        password: ''
      },
      rules: {
        name: [{ required: true, message: '请输入', trigger: 'blur' }],
        contact: [{ required: true, message: '请输入', trigger: 'blur' }],
        mobile: [
          { required: true, message: '请输入', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        ratio: [{ required: true, message: '请输入', trigger: 'blur' }],
        account: [{ required: true, message: '请输入', trigger: 'blur' }],
        password: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      loading: false
    }
  },
  methods: {
    handleClose() {
      // console.log('取消')
      this.$emit('update:dialogVisible', false)
      this.$refs.roleDialogForm.resetFields()
      this.roleForm = {}
    },
    async handleSumit() {
      this.$refs.roleDialogForm.validate()
      await addPartnerApi(this.roleForm)
      this.handleClose()
      this.$message.success('增添成功')
      this.$parent.BusinessDistrict()
    },
    handleChange(value) {
      console.log(value)
    }
  }
}
</script>

<style>

</style>
